package com.shop.appcontroller.login;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.bill99.seashell.common.util.MD5Util;

public class LoginController extends SimpleFormController {

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object cmd, BindException ex)
			throws Exception {
		LoginCommand info = (LoginCommand) cmd;

		String pwd = MD5Util.md5Hex(info.getPasssWord());
		String user = info.getUserName().toUpperCase();
		if (null != this.getUserMap().get(user)
				&& pwd.equals(this.getUserMap().get(user))) {
			Map usermap = new HashMap();
			usermap.put("userName", user);

		 
			// info.setUserNameSrc( CfautiCodeStrl.getpartnerName(user));
			request.getSession().setAttribute("userName", user);
			 
			if(user.equals("BILL")){
				return new ModelAndView(this.getAccount_view())
				.addAllObjects(usermap);
			}else{
				return new ModelAndView(this.getPartner_view())
				.addAllObjects(usermap);
			}

		}

		return new ModelAndView(this.getFail_view()).addObject("errormsg",
				"用户名或者密码错误");
	}

	private String fail_view;
	private String account_view;
	private String partner_view;
	private Map userMap;

	 
	public String getFail_view() {
		return fail_view;
	}

	public void setFail_view(String fail_view) {
		this.fail_view = fail_view;
	}

	public Map getUserMap() {
		return userMap;
	}

	public void setUserMap(Map userMap) {
		this.userMap = userMap;
	}

	public String getAccount_view() {
		return account_view;
	}

	public void setAccount_view(String account_view) {
		this.account_view = account_view;
	}

	public String getPartner_view() {
		return partner_view;
	}

	public void setPartner_view(String partner_view) {
		this.partner_view = partner_view;
	}
}
